def subsets(nums):
    """
    :type nums: List[int]
    :rtype: List[List[int]]
    """
    res = []
    res.append([])
    # 遍历每个元素
    for num in nums:
        # 临时数组
        temp = []
        # 遍历当前结果集，将当前结果集的每个元素(数组)中加入当前的num
        for i in res:
            r = i.copy()
            r.append(num)
            temp.append(r)
        # 当前temp追加到res中去
        res += temp
    return res


nums = [1, 2, 3]
print(subsets(nums))
# [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]
